package com.lanou.myapp.book.girlbook;

/**
 * Created by dllo on 16/1/15.
 */


import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.lanou.myapp.R;
import com.lanou.myapp.imageloader.GsonRequest;
import com.lanou.myapp.imageloader.VolleySingleton;

public class GirlBookFragment extends Fragment{
    private String url = "http://4g.if.qidian.com/Atom.axd/Api/BookStore/GetBookStoreList?sId=1";
    private Context context;
    private RecyclerView recyclerView;
    private GirlBookAdapter adapter;

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        this.context = context;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        recyclerView = (RecyclerView) getActivity().findViewById(R.id.recyclerView_girl_book);
        adapter = new GirlBookAdapter(getActivity());
        recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
        recyclerView.setAdapter(adapter);

        GsonRequest<GirlBookBeans> request = new GsonRequest<GirlBookBeans>(url, GirlBookBeans.class, new Response.Listener<GirlBookBeans>() {
            @Override
            public void onResponse(GirlBookBeans response) {
                adapter.addData(response.getGroup());
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {

            }
        });
        VolleySingleton.getInstance()._addRequest(request);

    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = LayoutInflater.from(context).inflate(R.layout.fragment_girl_book,null);
        return view;
    }
}
